package com.common.service.impl;

import com.common.entity.IdEntity;
import com.common.repostitory.CommonRepository;
import com.common.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 文 件 名 称：CommonServiceImpl.
 * 文 件 说 明：
 * 创   建   人：zpen.
 * 创 建 时 间：2018/6/5 13:57.
 */
@Repository("CommonService")
@Transactional
public class CommonServiceImpl<T extends IdEntity, PK extends Serializable>  implements CommonService<T,PK> {
    @Autowired
    CommonRepository commonRepository;

    @Override
    public T load(Class<T> entityName, PK id) {

        return  commonRepository.load(entityName,id);
    }

    @Override
    public List loadAll(Class<T> entityName) {
        return commonRepository.loadAll(entityName);
    }

    @Override
    public T getEntity(Class<T> entityName, PK id) {
        return commonRepository.getEntity(entityName,id);
    }

    @Override
    public List fillAll() {
        return null;
    }

    @Override
    public void persist(T entity) {
        commonRepository.persist(entity);
    }

    @Override
    public PK save(T entity) {
        try {
            return commonRepository.save(entity);
        }catch (Exception e){
            System.out.println(e);
            throw e;
        }
    }

    @Override
    public void saveOrUpdate(T entity) {
        commonRepository.saveOrUpdate(entity);
    }

    @Override
    public void deleteById(Class<T> entityName, PK id) {
        commonRepository.deleteById(entityName,id);
    }

    @Override
    public void delete(T entity) {
        commonRepository.delete(entity);
    }

    @Override
    public void batchDelete(Collection entitys) {
        commonRepository.batchDelete(entitys);
    }

    @Override
    public void batchDeleteByIds(Class<T> entityName, PK[] ids) {
        commonRepository.batchDeleteByIds(entityName,ids);
    }

    @Override
    public void executeSql(String sql, Object[] param) {
        commonRepository.executeSql(sql,param);
    }

    @Override
    public List<Map<String, Object>> findSql(String sql) {
        return commonRepository.findSql(sql);
    }

    @Override
    public List<Map<String, Object>> findSql(String sql, Object[] obj) {
        return commonRepository.findSql(sql,obj);
    }

    @Override
    public Map<String, Object> getMapSql(String sql, Object[] objs) {
        return commonRepository.getMapSql(sql,objs);
    }

    @Override
    public <T> T getEntityByProperty(Class<T> entityClass, String propertyName, Object value) {
        return commonRepository.getEntityByProperty(entityClass,propertyName,value);
    }
}
